package net.ojbk.timeSpace.test.beans;

import net.ojbk.timeSpace.test.common.api.APICodeConstant;

public class APIResult {

	private int code;
	private String message;
	private Object data;

	
	public static APIResult createSuccess(APICodeConstant aPICodeConstant, Object data) {
		return createWithCodeAndData(aPICodeConstant.getSuccessCode(), null, data);
	}

	public static APIResult createSuccessMessage(APICodeConstant aPICodeConstant, String message) {
		return createWithCodeAndData(aPICodeConstant.getSuccessCode(), message, null);
	}

	public static APIResult createError(APICodeConstant aPICodeConstant,String message) {
		return createWithCodeAndData(aPICodeConstant.getErrorCode(), message, null);
	}
	public static APIResult createFail(APICodeConstant aPICodeConstant,String message) {
		return createWithCodeAndData(aPICodeConstant.getFailCode(), message, null);
	}
	
	private static APIResult createWithCodeAndData(int code, String message, Object data) {
		APIResult result = new APIResult();
		result.setCode(code);
		result.setMessage(message);
		result.setData(data);
		return result;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "APIResult [code=" + code + ", message=" + message + ", data=" + data + "]";
	}

}